﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Diagnostics;

namespace EpiMapit
{
    public class RingGenerator
    {

        private int totalCasesInAllGroups;
        private Color[] colors;
        

        public RingGenerator(int totalCasesInAllGroups, params Color[] colors)
        {
            this.totalCasesInAllGroups = totalCasesInAllGroups;
            this.colors = colors;
        }

        public IEnumerable<IKmlFigure> GenerateFor(CaseSet caseSet, float unit, int levelOfDetail)
        {
            float size = 0;
            int i = 0;
            
            float total = caseSet.Levels.Values.Sum();
            //float biggest = (float)Math.Sqrt(Math.Log(total, ControlConstants.CircleScalingLogBase)+1) * unit / 2; 
            float biggest = (float)(unit * Math.Sqrt(total / totalCasesInAllGroups)); 

            foreach (var kaze in caseSet.Levels)
            {
				i++;
                if (kaze.Value == 0)
                    continue;

                size += kaze.Value;

                var circle = new Circle() { 
                    Lat = caseSet.Lat, 
                    Lon = caseSet.Lon,
                    Altitude = (ControlConstants.FirstRingAltitude * ControlConstants.RingAltitudeFactors[levelOfDetail])  + (ControlConstants.LodLevels - i) * ControlConstants.RingAltitudeFactors[levelOfDetail],
                    RadiusInKm = biggest * size / total,
                    Color = colors[(i-1) % colors.Length],
                };

                yield return circle;
            }
        }
    }
}
